package kt.com.bilin.coin.common

import android.view.View
import android.widget.Toast
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.launcher.ARouter
import com.bilin.coin.App

/*   TextView content;
   if (mToast == null) {
       mToast = new Toast(this);
       LayoutInflater layoutInflater = getLayoutInflater();
       View inflate = layoutInflater.inflate( R.layout.toast, null);
       content = inflate.findViewById(R.id.tv_toast);
       //content = new TextView(this);
       mToast.setView(inflate);
   } else {
       View mToastView = mToast.getView();
       content = mToastView.findViewById(R.id.tv_toast);
   }
   mToast.setDuration(Toast.LENGTH_SHORT);
   content.setText("      "+text+"      ");
   mToast.show();*/

//Toast.makeText(this,text,Toast.LENGTH_SHORT).show();
val Int.dp get() = (this * App.getApp().resources.displayMetrics.density + 0.5f).toInt()
fun dp2px(dpValue: Int) = (dpValue * App.getApp().resources.displayMetrics.density + 0.5f).toInt()
fun toastMessageLong(strIdes: Int) = Toast.makeText(App.getApp(), App.getApp().getString(strIdes), Toast.LENGTH_SHORT).show()
fun toastMessageLong(str: CharSequence?) = str?.let { Toast.makeText(App.getApp(), it, Toast.LENGTH_SHORT).show() }
fun getString(strIdes: Int) = App.getApp().getString(strIdes)
fun getString(strIdes: Int, vararg formatArgs: Any) = App.getApp().getString(strIdes, *formatArgs)
fun bindViewClick(listener: View.OnClickListener, vararg views: View) {
    for (it in views) {
        it.setOnClickListener(listener)
    }
}

fun java.io.Closeable.tryClose() {
    try {
        close()
    } catch (e: Exception) {

    }
}

var View.changeVisibility: Boolean
    get() = true
    set(value) {
        visibility = if (value) View.VISIBLE else View.GONE
    }
